(function(){
    //Section 1 : 按下自定义按钮时执行的代码
    var a= {
            exec:function(editor){
                layer.open({
                    id:'myscript',
                    type:2,
                    title:'公式编辑器',
                    content:'/album/script',
                    shade:false,
                    area:['500px','500px'],
                    btn:['确定'],
                    yes:function(index){
                        var iframe = $('#myscript').find('iframe').contents();
                        html2canvas(iframe.find('#resultField').find('.katex'),{
                            onrendered:function(canvas){
                                base64 = canvas.toDataURL("image/png");
                                if(base64){
                                    var html = $('#cke_testAsk').find('iframe').contents().find('p').html();
                                    var img = "<img src='"+base64+"' >";
                                    var textArea = $('#cke_testAsk').find('iframe').contents().find('p');
                                    textArea.html(html+img);
                                    layer.close(index);
                                }
                            }
                        });
                    }
                });
            }
        },
        //Section 2 : 创建自定义按钮、绑定方法
        b='askbutton';
    CKEDITOR.plugins.add(b,{
        init:function(editor){
            editor.addCommand(b,a);
            editor.ui.addButton('askbutton',{
                label:'Ask Button',
                icon: this.path + 'logo_ckeditor.png',
                command:b
            });
        }
    });
})();